﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using XMLGener.Data;
using XMLGener.interfaces;

namespace XMLGener.GUI.components
{
    /// <summary>
    /// 
    /// </summary>
    public partial class XFileSelector : UserControl, IXModuleField
    {
        /// <summary>
        /// 
        /// </summary>
        public XFileSelector()
        {
            InitializeComponent();
        }


        /// <summary>
        /// set attribute
        /// </summary>
        /// <param name="param"></param>
        public void setAttr(XModuleParam param)
        {
            this.label1.Text = param.name;
            this.id = param.id;
        }

        /// <summary>
        /// id represents name in settings (identification of setting)
        /// </summary>
        private string id = null;

        /// <summary>
        /// Source node
        /// </summary>
        private XMLGenerNode node = null;

        #region IXModuleField Members


        /// <summary>
        /// Set value
        /// </summary>
        /// <param name="node"></param>
        public void setXNode(XMLGenerNode node)
        {
            this.node = node;
            if (node != null)
                this.textBox1.Text = node.getSetting(id);
        }

        #endregion

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (node != null)
                node.setSetting(id, textBox1.Text);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                this.textBox1.Text = openFileDialog1.FileName;
                if (node != null)
                    node.setSetting(id, textBox1.Text);

            }
        }

      
    }
}
